<?php
require '../../config.php';
$query="SELECT * from rutas ORDER BY idrutas desc";
$resultset = mysql_query($query,$conexion);


if(!$resultset)
{
	mysql_close();
	echo json_encode('error en el query: ' . mysql_error());
}
elseif(!mysql_num_rows($resultset))
{
	mysql_close();
	echo "<button type='button' class='btn btn-info'   onclick='nuevaruta()'>Agregar nueva ruta&nbsp<span class= 'glyphicon glyphicon-plus'></span></button>";
}
else
{

	echo "<button type='button' class='btn btn-info'   onclick='nuevaruta()'>Agregar nueva ruta&nbsp<span class= 'glyphicon glyphicon-plus'></span></button><br>";
	echo   "<br><table class='table table-bordered'>";
	echo   "<tr class='active'>";
	echo   "<th>Identificador</th><th>N&uacute;mero de ruta</th><th>Nombre de la ruta</th><th>Descripci&oacute;n de la ruta</th><th>Opciones</th>";
	echo   "</tr>";
	echo   "<tbody>";
	$aux=0;
	while($row = mysql_fetch_assoc($resultset))
	{
		if($aux==0){
			$color="#FFFFFF";
			$aux=1;
		}else{
			$color="#F9F9F9";
			$aux=0;
		}
		echo ("<tr bgcolor='".$color."'>");
		echo   "<td>".$row['idrutas']."</td>";
		echo   "<td>".$row['numeroruta']."</td>";
		echo   "<td>"._convert($row['nombre'])."</td>";
		echo   "<td>"._convert($row['descripcion'])."</td>";
		echo   "<td><a href='#' <span class='glyphicon glyphicon-pencil'  onclick='modificar(".$row[idrutas].");'> Modificar</span></a> &nbsp;<a  href='#' <span class='glyphicon glyphicon-remove' onclick='eliminar(".$row[idrutas].")'> Eliminar</span></a></td>";
		echo   "</tr>";
	}
	echo   "</tbody>";
	echo   "</table>";
	mysql_close();

}


function _convert($content) {
	if(!mb_check_encoding($content, 'UTF-8')
	OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

		$content = mb_convert_encoding($content, 'UTF-8');

		if (mb_check_encoding($content, 'UTF-8')) {
			// log('Converted to UTF-8');
		} else {
			// log('Could not converted to UTF-8');
		}
	}
	return $content;
}

?>